package lee.vioson.remotedata

import lee.vioson.remotedata.bean.AppConfig
import lee.vioson.remotedata.bean.BaseListRsp
import lee.vioson.remotedata.bean.BaseRsp
import lee.vioson.remotedata.bean.Book
import lee.vioson.remotedata.bean.BookData
import lee.vioson.remotedata.bean.ChapterInfo
import lee.vioson.remotedata.bean.Feedback
import lee.vioson.remotedata.bean.FeedbackDetail
import lee.vioson.remotedata.bean.HomeData
import lee.vioson.remotedata.bean.LoginResult
import lee.vioson.remotedata.bean.requestbody.FeedbackBody
import lee.vioson.remotedata.bean.requestbody.FeedbackDetailRequestBody
import lee.vioson.remotedata.bean.requestbody.UniqueRequestBody
import okhttp3.RequestBody
import okhttp3.ResponseBody
import retrofit2.Call
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Streaming
import retrofit2.http.Url

/**
 *Author:viosonlee
 *Date:2023/5/31
 *DESCRIPTION:
 */
interface ApiServices {
    /**
     * init
     * @param requestBody :{ "uniqueId":String }
     */
    @POST(ApiUrl.init)
    suspend fun init(@Body requestBody: RequestBody): BaseRsp<AppConfig>

    /**
     * @param body :{
     *  "uniqueId":String
     *  "email":String
     * }
     */
    @POST(ApiUrl.send_email_code)
    suspend fun sendEmailCode(@Body body: RequestBody): BaseRsp<Map<String, String>>

    /**
     * @param body :{
    "uniqueId": "string",
    "email": "string",
    "password": 0,
    "emailCode": 0,
    "customerSource": 0,
    "areaCode": 0,
    "language": 0
    }
     */
    @POST(ApiUrl.register)
    suspend fun register(@Body body: RequestBody): BaseRsp<LoginResult>

    /**
     * @param body:
     * {
    "uniqueId": "string",
    "email": "string",
    "password": 0,
    "loginType": 0 //1邮箱 2快捷登录
    }
     */
    @POST(ApiUrl.login)
    suspend fun login(@Body body: RequestBody): BaseRsp<LoginResult>

    /**
     * @param body:
     * {
    "uniqueId": "string",
    "customerSource": "string"
    }
     */
    @POST(ApiUrl.anonymous_login)
    suspend fun anonymousLogin(@Body body: RequestBody): BaseRsp<LoginResult>

    /**
     * @param body:
     * {
    "uniqueId": "string",
    "email": "string",
    "password": 0,
    "emailCode": 0
    }
     */
    @POST(ApiUrl.forget_password)
    suspend fun forgetPassword(@Body body: RequestBody): BaseRsp<LoginResult>

    /**
     * refresh token
     * @param body:
     *
     */
    @POST(ApiUrl.get_login_user_info)
    suspend fun getLoginUserInfo(@Body body: RequestBody): BaseRsp<LoginResult>

    /**
     * fetch home data
     * @param body :
     * {
    "uniqueId": "string"
    }
     */
    @POST(ApiUrl.home_data)
    suspend fun fetchHomeData(@Body body: RequestBody): BaseRsp<HomeData>

    /**
     * @param body :{
    "pageSize": 0,
    "pageIndex": 0
    }
     */
    @POST(ApiUrl.my_favorites_book_list)
    suspend fun fetchMyFavoritesBookList(@Body body: RequestBody): BaseListRsp<Book>

    /**
     * @param body :{
    "uniqueId": "string",
    "pageSize": "string",
    "pageIndex": "string"
    }*
     */
    @POST(ApiUrl.find_recommend_book_list)
    suspend fun fetchRecommendBookList(@Body body: RequestBody): BaseListRsp<Book>

    /**
     * book detail
     * @param body:{
    "uniqueId": "string",
    "bookId": "string"
    }
     */
    @POST(ApiUrl.find_book_detail)
    suspend fun fetchBookDetail(@Body body: RequestBody): BaseRsp<BookData>

    @Streaming
    @GET
    fun downloadFile(@Url url: String): Call<ResponseBody>

    /**
     * @param body:
     * {
    "uniqueId": "string",
    "bookId": "string",
    "action": "string"
    }
     */
    @POST(ApiUrl.do_favorites)
    suspend fun doFavorite(@Body body: RequestBody): BaseRsp<*>

    /**
     * @param body:{
    "pageSize": 0,
    "pageIndex": 0,
    "searchText": "string"
    }
     */
    @POST(ApiUrl.find_book_list)
    suspend fun doSearch(@Body body: RequestBody): BaseListRsp<Book>

    /**
     * mark viewed once
     * @param body :
     * {
    "uniqueId": "string",
    "bookId": "string"
    }
     */
    @POST(ApiUrl.view_book)
    suspend fun markBookView(@Body body: RequestBody): BaseRsp<Long>

    /**
     * @param body:
     * {
    "uniqueId": "string",
    "pageSize": "string",
    "pageIndex": "string"
    }
     */
    @POST(ApiUrl.find_favorites_book_list)
    suspend fun fetchMostFavoritesBooks(@Body body: RequestBody): BaseListRsp<Book>

    /**
     * @param body:{
    "uniqueId": "string",
    "chapterId": "string"
    }
     */
    @POST(ApiUrl.find_chapter_detail)
    suspend fun fetchChapterDetail(@Body body: RequestBody): BaseListRsp<ChapterInfo>

    /**
     * @param body :{
    "uniqueId": "string",
    "typeCode": "string",
    "type": "string",
    "messageContent": "string",
    "messagePhoto": "string",
    "parentMessageId": "string"
    }
     *
     * @return {
    "success": true,
    "code": 0,
    "msg": "string",
    "data": {
    "msgId": "string"
    }
    }
     */
    @POST(ApiUrl.save_feedback)
    suspend fun saveFeedback(@Body body: FeedbackBody): BaseRsp<Map<String, String>>

    @POST(ApiUrl.find_feedback_list)
    suspend fun fetchFeedbackList(@Body body: UniqueRequestBody): BaseListRsp<Feedback>

    @POST(ApiUrl.find_feedback_detail)
    suspend fun fetchFeedbackDetail(@Body body: FeedbackDetailRequestBody): BaseListRsp<FeedbackDetail>
}